package com.icode.core.model.house;

import com.icode.core.model.AbstractEntity;

import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sunk
 * Date: 15-1-4
 * Time: 上午10:29
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "building_type")
public class BuildingType extends AbstractEntity {
    private String name;
    private String area;
    private String price;

    @Column(name = "building_area")
    private String buildingArea;

    @Column(name = "extra_area")
    private String extraArea;

    @Column(name = "house_type")
    @Enumerated(EnumType.STRING)
    private HouseType houseType;

    @Column(name = "person_num")
    private String personNum;

    @OneToMany(cascade = CascadeType.REMOVE)
    @JoinColumn(name = "building_type_id")
    private List<HouseInfo> houseInfos;

    @ManyToOne
    @JoinColumn(name = "house_base_id")
    private HouseBase houseBase;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "building_type_id")
    private List<BuildingTypeImage> buildingTypeImages;

    public BuildingType() {
    }

    public BuildingType(String name, String area, String price, HouseType houseType, String personNum, HouseBase houseBase, String buildingArea, String extraArea) {
        this.name = name;
        this.area = area;
        this.price = price;
        this.houseType = houseType;
        this.personNum = personNum;
        this.houseBase = houseBase;
        this.buildingArea = buildingArea;
        this.extraArea = extraArea;
    }

    public void initBuildingType(String name, String area, String price, HouseType houseType, String personNum, HouseBase houseBase, String buildingArea, String extraArea){
        this.name = name;
        this.area = area;
        this.price = price;
        this.houseType = houseType;
        this.personNum = personNum;
        this.houseBase = houseBase;
        this.buildingArea = buildingArea;
        this.extraArea = extraArea;
    }

    public String area() {
        return area;
    }

    public HouseType houseType() {
        return houseType;
    }

    public String personNum() {
        return personNum;
    }

    public List<HouseInfo> houseInfos() {
        return houseInfos;
    }

    public String price() {
        return price;
    }

    public String name() {
        return name;
    }

    public HouseBase houseBase() {
        return houseBase;
    }

    public List<BuildingTypeImage> buildingTypeImages() {
        return buildingTypeImages;
    }

    public String buildingArea() {
        return buildingArea;
    }

    public String extraArea() {
        return extraArea;
    }

    public void initHouseTypeImages(List<BuildingTypeImage> buildingTypeImages) {
        if (this.buildingTypeImages == null) {
            this.buildingTypeImages = buildingTypeImages;
        } else {
            for (BuildingTypeImage b : buildingTypeImages) {
                this.buildingTypeImages().add(b);
            }
        }
    }
}
